var prefix = ctx + "/system/commonreportstatistics";

$(document).ready(function() {

	var div_report_height = $(window).height() - 255;
	div_report.style.height = div_report_height + 'px';

	 
});

function fun_addModel() {
	var param = Get_Params();
	if (Vel_Param(param)) {
		$.ajax({
			cache : true,
			type : "POST",
			url : prefix + "/save",
			data : param,
			async : false,
			error : function(request) {
				parent.layer.alert("Connection error");
			},
			success : function(data) {
				if (data.code == 0) {
					parent.layer.msg("操作成功");
					parent.fun_init();// 执行父页面的事件
					var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
					parent.layer.close(index);

				} else {
					parent.layer.alert(data.msg)
				}
			}
		});
	}
}

function fun_Close() {
	var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
	parent.layer.close(index);
}

function Get_Params() {
	return {

		sid : $("#sid").val(),// $("#编号").val()
		sname : $("#SNAME").val(),// $("#报表标题").val()

		stype : "1",// $("#类型").val() 1 是 报表 2 图表

		computerTsql : $("#COMPUTER_TSQL").val(),// $("#table-SQl语句").val()

	};
}

function Vel_Param(param) {
	var msg = "";

	if (msg.length > 0) {
		parent.layer.msg(msg);
		return false;
	}

	else {
		return true;
	}
}

function ExecutClick() {
	div_report.style.width = $("#REPORT_DESCRIPTION").width() + 105 + 'px';
	var REPORT_SQL_ = document.all.COMPUTER_TSQL.value.toUpperCase();

	$
			.ajax({
				type : "get",

				url : prefix + "/listReport",// '../../PublicInfoManage/COMMONREPORT/GetExecuteData',
				data : {
					sqlContent : REPORT_SQL_,
					SQL_PARAMS : $('#SQL_PARAMS').val()
				},
				async : false,
				success : function(data) {

					var showtable = "<table class='hovertable'>";

					$
							.each(
									data,
									function(index, item) {

										if (index == 0) {
											showtable += "<tr>";
											$.each(item, function(_key) {
												//console.log(_key);
												showtable += "<th>" + _key
														+ "</th>"; // 拼接：表格标题

											});
											showtable += "</tr>";
										}
										showtable += "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";
										$.each(item, function(_key) {

											if (item[_key] == null) {
												item[_key] = "-"
											}
											showtable += "<td>" + item[_key]
													+ "</td>"; // 拼接：表格内容
										});
										showtable += "</tr>";

									});
					showtable += "</table>";
					$("#div_report").html(showtable);
				}

			});

}
